#include "list.h"

namespace yyp
{
	void ListTest1()
	{
		list<int> l1;
		list<int> l2(5);
		list<int> l3(5, 3);
		list<int> l4{ 1, 2, 3, 4, 5 };
		list<int> l5(l4.begin(), l4.end());
		list<int> l6(++l4.begin(), --l4.end());

		Print(l1);
		Print(l2);
		Print(l3);
		Print(l4);
		Print(l5);
		Print(l6);
		cout << "****************\n";

		list<int> l7 = l6;

		Print(l7);
		l7 = l4;
		Print(l7);
	}

	void ListTest2()
	{
		list<int> l1;

		l1.push_back(6);
		l1.push_back(7);
		l1.push_back(8);
		l1.push_back(9);
		l1.push_front(5);
		l1.push_front(4);
		l1.push_front(3);
		l1.push_front(2);
		l1.push_front(1);
		Print(l1);

		l1.front() = 10;
		l1.back() = 90;
		Print(l1);

		l1.pop_back();
		Print(l1);
		l1.pop_back();
		Print(l1);
		l1.pop_front();
		Print(l1);
		l1.pop_front();
		Print(l1);

		l1.erase(++l1.begin());
		l1.erase(--l1.end());
		Print(l1);
	}

	void ListTest3()
	{
		list<int> l1({ 1, 2, 3, 4, 5 });

		list<int>::reverse_iterator rit1;
		for (rit1 = l1.rbegin(); rit1 != l1.rend(); ++rit1)
		{
			*rit1 += 2;
			cout << *rit1 << " ";
		}
		cout << endl;

		const list<int> l2(l1);
		for (list<int>::const_reverse_iterator rit2 = l2.rbegin(); rit2 != l2.rend(); ++rit2)
		{
			//*rit2 += 2;
			cout << *rit2 << " ";
		}
		cout << endl << "*********************\n";

		struct A
		{
			A(int a1 = 1, int a2 = 2)
				: _a1(a1)
				, _a2(a2)
			{}

			int _a1;
			int _a2;
		};

		list<A> la;
		la.push_back(A(1, 1));
		la.push_back(A(2, 2));
		la.push_back(A(3, 3));

		for (list<A>::iterator it3 = la.begin(); it3 != la.end(); ++it3)
		{
			cout << it3->_a1 << " " << it3->_a2 << endl;
		}
		cout << endl;

		list<A> laa = la;
		for (list<A>::reverse_iterator rit3 = laa.rbegin(); rit3 != laa.rend(); ++rit3)
		{
			cout << rit3->_a1 << " " << rit3->_a2 << endl;
		}
		cout << endl;
	}
}

int main()
{
	yyp::ListTest1();
	yyp::ListTest2();
	yyp::ListTest3();

	return 0;
}